import { getUserMenuList } from '@/api/user'


// 定义状态
const state = {

    init: false,//是否已加载用户权限
    menuList: [],//用户所拥有的菜单
    btnList: [] //用户所有的按钮权限
}

// 改变状态值
const mutations = {
    SET_SYSTEM_MENU: (state, data) => {
        state.init = true,
            state.menuList = data.menuList,
            state.btnList = data.btnList
    }
}
// 定义行为
const actions = {

    GetUserMenu({ commit }) {
        return new Promise((resolve, reject) => {
            const userId = 1
            //  这里的用户id 后期会再cookie中直接获取
            if (userId) {
                getUserMenuList(userId).then(res => {
                    commit('SET_SYSTEM_MENU', res.data)
                    resolve()
                }).catch(error => {
                    reject(error)
                })
            }

        })
    }

}

export default {
    namespaced:true,//引用里需要制定模块名称如：/menu/GetUserMenu
    state,
    mutations,
    actions
}